package com.example.administrator.yuejian2.fragment;


import android.content.Intent;
import android.os.Bundle;

import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.support.v4.app.Fragment;
import com.example.administrator.yuejian2.R;
import com.example.administrator.yuejian2.RetrofitListener.RetrofitListener;
import com.example.administrator.yuejian2.adapter.MasterAdapter;
import com.example.administrator.yuejian2.bean.MasterBean;
import com.example.administrator.yuejian2.model.MasterModel;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class ClubMasterFragment extends Fragment {

    private String c_id;
    private RetrofitListener<List<MasterBean>> listener;
    private RecyclerView recyclerView;
    private MasterAdapter masterAdapter;
    private RecyclerView.LayoutManager layoutManager;
    public ClubMasterFragment() {
        // Required empty public constructor
    }

    public void getClubMasterList()
    {
        MasterModel masterModel=new MasterModel();
        masterModel.masterList(c_id,listener);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
        Intent intent=getActivity().getIntent();
        c_id=(String)intent.getStringExtra("c_uid");
        getClubMasterList();

    }
    private void initView(View v)
    {
        recyclerView=v.findViewById(R.id.master_recyclerView);
        layoutManager=new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        masterAdapter=new MasterAdapter(getActivity());
        recyclerView.setAdapter(masterAdapter);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        listener=new RetrofitListener<List<MasterBean>>() {
            @Override
            public void onSuccess(List<MasterBean> masterBeans, int flag) {
                masterAdapter.getMasterList(masterBeans);
            }

            @Override
            public void onFail() {

            }
        };

        return inflater.inflate(R.layout.fragment_club_master, container, false);
    }

}
